package com.f5.management.dao;

import com.f5.management.entity.Community;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CommunityDAO {
    Community get(int id);
    Community getByName(String name);

    List<Community> list();

    //添加小区信息
    @Insert("insert into community(id,serialNumber,name,location,area,peopleNumber,greening,pic,developer,propertyCompany," +
            "createTime) values(default,#{serialNumber},#{name},#{location},#{area}," +
            "#{peopleNumber},#{greening},#{pic},#{developer},#{propertyCompany},#{createTime})")
    int add(Community community);

    //查询存在的小区及编号
    @Select("select count(id) from community")
    int count();

    //更改状态
    @Update("update community set status=#{status} where id = #{id}")
    int updateStatus(@Param("id") int id, @Param("status") boolean status);

    //分页查询
    List<Community> findAll();

    //更改信息
    @Update("update community set serialNumber=#{serialNumber},name=#{name},location=#{location}," +
            "area=#{area},peopleNumber=#{peopleNumber},greening=#{greening},developer=#{developer}" +
            ",propertyCompany=#{propertyCompany} where id = #{id}")
    int updateInfo(Community community);

    //删除信息
    @Delete("delete from community where id = #{id}")
    int delInfo(int id);

    //通过名字查询
    List<Community> findByName(String serialNumber,String name);

    //通过小区名字查询cid
    @Select("select id from community where name = #{name}")
    int findCidByName(String name);

    //id查询数据进行修改
    @Select("select * from community where id = #{id}")
    Community findById(int id);

    //查询编号是否存在
    @Select("select serialNumber from community where serialNumber = #{serialNumber}")
    String selectNumber(String serialNumber);
}
